﻿package com.zouloux.physics 
{
	import com.zouloux.abstract.IPhysicsObject;
	import com.zouloux.core.base.DocumentBase;
	import flash.events.MouseEvent;
	import org.papervision3d.objects.primitives.Sphere;
	
	/**
	 * ...
	 * @author ZoulouX
	 */
	public class PhysicsPaperSphere extends PhysicsSphere implements IPhysicsObject
	{
		// La sphere 3D
		protected var _sphere				:Sphere;
		
		protected var _toY					:Boolean			= false;
		
		// Les getters
		public function get sphere ():Sphere
		{
			return _sphere;
		}
		public function get toY():Boolean { return _toY; }
		
		// Les setters
		public function set sphere (value:Sphere):void 
		{
			_sphere = value;
		}
		override public function set radius (value:Number):void
		{
			_radius = value;
			
			graphics.clear();
			graphics.beginFill(0);
			graphics.drawCircle(0, 0, value);
		}
		public function set toY(value:Boolean):void 
		{
			_toY = value;
		}
		
		
		
		// Le constructeur
		public function PhysicsPaperSphere (pRadius:Number = 0)
		{
			super(pRadius);
			
			addEventListener(MouseEvent.MOUSE_DOWN, startMouseDrag);
			DocumentBase.stage.addEventListener(MouseEvent.MOUSE_UP, stopMouseDrag);
		}
		
		
		// Ecraser l'upadte
		override public function update ():void
		{
			super.update();
			
			_sphere.x = x;
			if (_toY)
				_sphere.y = y;
			else
				_sphere.z = y;
		}
	}
}